#ifndef MQCLIENT61850_H
#define MQCLIENT61850_H

#include <QObject>
#include <QVector>

#include "iec61850_client.h"

#define _IPV4_ADDR_ "10.37.49.159"
#define _IPV4_PORT_ 102

//struct _61850_FCDA_STRUCT_ {
//    QString name;
//    QString type;
//    QString value;
//    QVector<_61850_FCDA_STRUCT_> structs;
//};

struct _61850_FCDA_ {
    QString name;
    QString type;
    QString fc;
    int type_num;
    QString value;
    QVector<_61850_FCDA_> structs;
};

struct _61850_DATASET_ {
    QString name;
    QString type;
    QVector<_61850_FCDA_> fcdas;
};

struct _61850_DA_ {
    QString name;
    QString type;
    QString fc;
    int type_num;
    QString value;
    QVector<_61850_DA_> structs;
};

struct _61850_DO_ {
    QString name;
    QString type;
    QVector<_61850_DA_> das;
};

struct _61850_LN_ {
    QString name;
    QVector<_61850_DO_> dos;
    QVector<_61850_DATASET_> dataset;
};

struct _61850_LD_ {
    QString name;
    QVector<_61850_LN_> lns;
};

class MQClient61850:public QObject
{
    Q_OBJECT
public:
    MQClient61850();
    QVector<_61850_LD_> GetDirVec(){
        return m_dirVec;
    }
    void ClientUpdate();
    void WriteVal(QString locate, int type_num, QString type_extra, QVariant valueVar);

private:
    void ClientInit();
    _61850_FCDA_ GetFedaStruct(MmsValue *tmms_fcda);
    _61850_FCDA_ GetFedaStruct(MmsValue *tmms_fcda, char *reference);
    _61850_DA_ GetDaStruct(MmsValue *tmms_fcda);
    _61850_DA_ GetDaStruct(MmsValue *tmms_fcda, char *reference);

    IedConnection m_iedConnectHandle;
    QVector<_61850_LD_> m_dirVec;
};


typedef struct sMmsValue MmsValue;

typedef struct ATTRIBUTE_PACKED {
    uint8_t size;
    uint8_t maxSize;
    uint8_t* octets;
} Asn1PrimitiveValue;

struct ATTRIBUTE_PACKED sMmsValue {
    MmsType type;
    uint8_t deleteValue;
    union uMmsValue {
        MmsDataAccessError dataAccessError;
        struct {
            int size;
            MmsValue** components;
        } structure;
        bool boolean;
        Asn1PrimitiveValue* integer;
        struct {
            uint8_t exponentWidth;
            uint8_t formatWidth; /* number of bits - either 32 or 64)  */
            uint8_t buf[8];
        } floatingPoint;
        struct {
            uint16_t size;
            uint16_t maxSize;
            uint8_t* buf;
        } octetString;
        struct {
            int size;     /* Number of bits */
            uint8_t* buf;
        } bitString;
        struct {
            char* buf;
            int16_t size; /* size of the string, equals the amount of allocated memory - 1 */
        } visibleString;
        uint8_t utcTime[8];
        struct {
            uint8_t size;
            uint8_t buf[6];
        } binaryTime;
    } value;
};

#endif // MQCLIENT61850_H
